﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DepartmentManagement
{
    public partial class frmLogin : Form
    {
        #region Logic Functions
        private void fillLoginControls()
        {
            cmbUserName.DataSource = Entity.Account.GetAllAccounts();
            cmbUserName.SelectedIndex = -1;
            txtPassword.Text = string.Empty;
        }

        #endregion

        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            fillLoginControls();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            Entity.Account loginAccount = new Entity.Account(cmbUserName.Text, txtPassword.Text);

            loginAccount.Login();

            if (!loginAccount.Logged)
            {
                MessageBox.Show("用户名或者密码不正确，请重试");

                fillLoginControls();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            (new TestForm()).Show();
        }
    }
}
